/*
 * @Author: CQJ
 * @Date: 2022-08-25 20:00:27
 * @LastEditors: CQJ
 * @LastEditTime: 2022-09-13 23:12:48
 * @Description:
 */
import { reactive } from 'vue'
import type { SlideListData } from '@/types/advertising/slideAd'

type Key = string
interface SlideAdState {
  // 全部状态
  status: number | undefined
  // 广告id
  id: string | undefined
  name: string | undefined //影人名称关键词
}

// 广告状态管理
export const slideAdState = reactive<SlideAdState>({
  status: undefined,
  id: undefined,
  name: undefined
})
interface StatusState {
  adList: SlideListData[]
  isEdit: boolean
  addFilmMaker: boolean
  selectedRowKeys: Key[]
  slideVisible: boolean
}
// 状态管理
export const statusState = reactive<StatusState>({
  adList: [],
  isEdit: false,
  addFilmMaker: false,
  selectedRowKeys: [],
  slideVisible: false
})
export const resetState = () => {
  let key: keyof SlideAdState
  for (key in slideAdState) {
    slideAdState[key] = undefined
  }
}
const addressReg = /(http|https):\/\/([\w.]+\/?)\S*/
const checkAddress = (rule: any, value: any, callback: any) => {
  if (!value) {
    return Promise.reject('请输入跳转链接')
  } else if (!addressReg.test(value)) {
    return Promise.reject('请输入https://或http://开头的链接')
  } else {
    return Promise.resolve()
  }
}
export const formRules = reactive({
  name: [{ required: true, message: '请输入广告标题' }],
  jump_addr: [{ required: true, validator: checkAddress, trigger: 'blur' }],
  img_url: [{ required: true, message: '请配置广告图文' }],
  img_type: [{ required: true, message: '请选择图文类型' }],
  show_position: [{ required: true, message: '请选择投放位置' }]
})
